# This file contains snippets that are always defined. I personally
# have snippets for signatures and often needed texts

# sligthly lower priority than everything else since specialized versions
# should overwrite. The user needs to adjust her priority in her snippets to
# ~-55 so that other filetypes will still overwrite.
priority -59

global !p
import hashlib
import secrets
import sys
from datetime import datetime
from vimsnippets import foldmarker, make_box, get_comment_format
endglobal


#snippet "be(gin)?( (\S+))?" "begin{} / end{}" br
#\begin{${1:`!p
#snip.rv = match.group(3) if match.group(2) is not None else "something"`}}
#    ${2:${VISUAL}}
#\end{$1}$0
#endsnippet


snippet yw "YY week WW . day" i
`!v strftime("%gw%Vd%u%H")` 
endsnippet

snippet rd "random  number" i
`!p if not snip.c: snip.rv= str(secrets.randbits(33)) ` $0
endsnippet

# below format() requires python2 interpret
snippet r3 "random  number" i
`!p if not snip.c: snip.rv= '{:03d}'.format( secrets.randbits(9)) ` $0
endsnippet

#`!p if not snip.c: snip.rv= str(secrets.randbits(13)) ` $0
# snippet r4 "random  number" i
# `!p if not snip.c: snip.rv= str(secrets.randbits(13)) ` $0
# endsnippet

snippet r4 "random  number" i
`!p if not snip.c: snip.rv= '{:04d}'.format( secrets.randbits(13)) ` $0
endsnippet

snippet rh "random  hex 128" i
`!p if not snip.c:
	kyb4=bytes(str(secrets.randbits(33)), encoding='utf-8' )
	snip.rv= hashlib.sha3_512(kyb4).hexdigest()
` $0
endsnippet

snippet wx "timestamp in comment box" b
`!p if not snip.c: 
	tds= datetime.today().strftime("%gw%Vd%u%H")
	kyb4=bytes(str(secrets.randbits(33)), encoding='utf-8' )
	sha0 = hashlib.sha3_512(kyb4).hexdigest()
	sha1= sha0[0:10]
	s1 = f"{tds}_{sha1}"
	box = make_box(len(s1))
	snip.unshift(10)
	snip += f"{box[0]}\n{box[1]}{s1}{box[2]}\n{box[3]}"
`
$0
endsnippet

#`!v strftime("%yww%Vd%u%H") . "_". split( reltimestr(reltime()), '\.')[1] ` 
snippet wr "YY workweek W  day random" i
`!p if not snip.c: 
	tds= datetime.today().strftime("%gw%Vd%u%H")
	m3902 = int(datetime.today().strftime("%M")) #rounding minutes into 10's
	m3903 = str( (m3902+5)//10 )
	kyb4=bytes(str(secrets.randbits(33)), encoding='utf-8' )
	sha0 = hashlib.sha3_512(kyb4).hexdigest()
#	sha1= sha0[0:10]
	sha1= sha0[0:9]
#	snip.rv= f"{tds}_{m3903}_{sha1}"
	snip.rv= f"{tds}_{m3903}{sha1}"
`
endsnippet
#	snip.rv= f"{tds}_{secrets.randbits(33)}"`

snippet bc
${VISUAL:dollar_per_share/\/([^\\\n]*)\n?/ + \n $1/g} + ${2:share}


endsnippet
#${VISUAL:dollar_per_share/\// + \n/} +  ${2:share}

snippet ( "parenthesis on block"
(${1:${VISUAL:contents}})$0
endsnippet

snippet { "braces on block"
{${1:${VISUAL:contents}}}$0
endsnippet

snippet /* "C-comment on block"
/* ${1:${VISUAL:contents}} */$0
endsnippet
